package com.yanqu.road.server.cmd.activity.shushan;


import com.yanqu.road.pb.activity.ShuShanProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.manger.activity.shushan.ShuShanMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameProtocol;

/**
 * @Description
 * @Author cwq
 * @Data 2022/1/20 15:28
 */
@Cmd(code = GameProtocol.S_SHUSHAN_DISPATCH_LILIAN, desc = "派遣历练 / 或者 领取坑位奖励")
public class ShuShanDispatchLiLianCmd extends AbstractCommand {
    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        ShuShanProto.ShuShanDispatchLiLianReqMsg reqMsg = ShuShanProto.ShuShanDispatchLiLianReqMsg.parseFrom(packet.getBytes());
        ret = ShuShanMgr.canEntryActivity(player, reqMsg.getActivityId());
        if (ret != 0) {
            return;
        }

        player.sendPacket(ClientProtocol.U_SHUSHAN_DISPATCH_LILIAN, ShuShanMgr.dispatch(player, reqMsg.getId(), reqMsg.getType(), reqMsg.getDiscipleId()));
    }

    @Override
    public void sendData(GamePlayer player) {
        if (ret != 0) {
            ShuShanProto.ShuShanDispatchLiLianRespMsg.Builder builder = ShuShanProto.ShuShanDispatchLiLianRespMsg.newBuilder();
            builder.setRet(ret);
            player.sendPacket(ClientProtocol.U_SHUSHAN_DISPATCH_LILIAN, builder);
        }
    }
}
